package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.VariousKindsPicVo;
import com.ruoyi.system.domain.bo.VariousKindsPicBo;
import com.ruoyi.system.service.IVariousKindsPicService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 照片Controller
 *
 * @author ruoyi
 * @date 2022-03-15
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/kindsPic")
public class VariousKindsPicController extends BaseController {

    private final IVariousKindsPicService iVariousKindsPicService;

    /**
     * 查询照片列表
     */
    @SaCheckPermission("system:kindsPic:list")
    @GetMapping("/list")
    public TableDataInfo<VariousKindsPicVo> list(@Validated(QueryGroup.class) VariousKindsPicBo bo, PageQuery pageQuery) {
        return iVariousKindsPicService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出照片列表
     */
    @SaCheckPermission("system:kindsPic:export")
    @Log(title = "照片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated VariousKindsPicBo bo, HttpServletResponse response) {
        List<VariousKindsPicVo> list = iVariousKindsPicService.queryList(bo);
        ExcelUtil.exportExcel(list, "照片", VariousKindsPicVo.class, response);
    }

    /**
     * 获取照片详细信息
     */
    @SaCheckPermission("system:kindsPic:query")
    @GetMapping("/{id}")
    public R<VariousKindsPicVo> getInfo(
                                                  @NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return R.ok(iVariousKindsPicService.queryById(id));
    }

    /**
     * 新增照片
     */
    @SaCheckPermission("system:kindsPic:add")
    @Log(title = "照片", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody VariousKindsPicBo bo) {
        return toAjax(iVariousKindsPicService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改照片
     */
    @SaCheckPermission("system:kindsPic:edit")
    @Log(title = "照片", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody VariousKindsPicBo bo) {
        return toAjax(iVariousKindsPicService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除照片
     */
    @SaCheckPermission("system:kindsPic:remove")
    @Log(title = "照片", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iVariousKindsPicService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
